package com.yuexunit.finance.project.service;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.yuexunit.finance.project.entity.FinanceEmployeeEntity;
import com.yuexunit.inject.annotation.Implements;
import com.yuexunit.persist.PersistUtil;

/**
 * Created by Slevenc on 2015/6/1.
 */
@Implements(FinanceEmployeeService.class)
public class FinanceEmployeeServiceImpl implements FinanceEmployeeService {

	@Override
	public FinanceEmployeeEntity inquireEmployee(Long empId) {
		if (empId == null) {
			return null;
		}
		FinanceEmployeeEntity en = PersistUtil.get(FinanceEmployeeEntity.class, empId);
		return en;
	}
	
	@Override
	public FinanceEmployeeEntity inquireEmployeeByAccountId(Long accountId) {
		if (accountId == null) {
			return null;
		}
		DetachedCriteria criteria = DetachedCriteria.forClass(FinanceEmployeeEntity.class);
		criteria.add(Restrictions.eq("accountId", accountId));
		List<FinanceEmployeeEntity> list = PersistUtil.get(criteria);
		if (!list.isEmpty()) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public List<FinanceEmployeeEntity> inquireEmployList() {
		DetachedCriteria criteria = DetachedCriteria.forClass(FinanceEmployeeEntity.class);
		return PersistUtil.get(criteria);
	}

	@Override
	public List<FinanceEmployeeEntity> inquireEmployLikeList(String name) {
		DetachedCriteria criteria = DetachedCriteria.forClass(FinanceEmployeeEntity.class);
		criteria.add(Restrictions.like("name", "%" + name + "%"));
		return PersistUtil.get(criteria);
	}
}
